﻿using System;
using System.Reflection;

namespace Glue.Internals
{
    internal partial class AccessorFactory
    {
        public IObjectMemberAccessor Create(PropertyInfo member)
        {
            return new PropertyAccessor(member);
        }

        public IObjectMemberAccessor Create(MethodInfo methodInfo)
        {
            if (methodInfo.ReturnType == typeof(void))
                throw new ArgumentException("Method must have a return value: " + methodInfo.Name);
            if (methodInfo.GetParameters().Length > 0)
                throw new ArgumentException("Method can't have parameters: " + methodInfo.Name);
            return new MethodAccessor(methodInfo);
        }

        public IObjectMemberAccessor Create(FieldInfo fieldInfo)
        {
            return new FieldAccessor(fieldInfo);
        }
    }
}
